package com.plian.system.controller.hr.employment;

import com.plian.Tools.base.BaseController;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.dto.hr.employment.EnterpriseEmploymentDTO;
import com.plian.system.model.CommonCode;
import com.plian.system.model.ObjResult;
import com.plian.system.service.hr.employment.IEnterpriseEmploymentService;
import com.plian.system.service.wf.FormWorkflowService;
import com.plian.system.vo.report.ReportReturnVO;
import com.plian.system.wrapper.hr.employment.EnterpriseEmploymentWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

/**
 * 企业用工管理主表 控制器
 * 本业务不存在查重要求
 * @author gangan
 * @since 2019-11-12
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("api/enterpriseemployment")
public class EnterpriseEmploymentController extends BaseController {

	private IEnterpriseEmploymentService enterpriseEmploymentService;

	private FormWorkflowService formWorkflowService;

	private EnterpriseEmploymentWrapper enterpriseEmploymentWrapper;


//    /**
//    * 详情
//    */
//	@PostMapping("/detail")
//	public R<EnterpriseEmploymentVO> detail(@Valid @RequestBody EnterpriseEmployment enterpriseEmployment) {
//		EnterpriseEmployment detail = enterpriseEmploymentService.getOne(Condition.getQueryWrapper(enterpriseEmployment));
//		EnterpriseEmploymentVO enterpriseEmploymentVO = enterpriseEmploymentWrapper.entityToVO(detail);
//		return R.data(enterpriseEmploymentVO);
//	}
//
//	/**
//	* 分页 企业用工管理主表
//	*/
//	@PostMapping("/list")
//	public ListResult<EnterpriseEmploymentVO> list(@Valid @RequestBody Query query) {
//		if(query.getAscs()==null&&query.getDescs()==null){
//			query.setDescs("create_time");
//		}
//
//		List<SearchEntity> entityList = query.getSearch();
//		QueryWrapper<EnterpriseEmployment> queryWrapper = SearchParamEntiy.getQueryWrapper(
//				Condition.getQueryWrapper(new EnterpriseEmployment()), entityList
//		);
//
//		TokenSearch<EnterpriseEmployment> tokenSearch = new TokenSearch<>();
//		tokenSearch.addTokenQuery(queryWrapper, query);
//
//		IPage<EnterpriseEmployment> pages = enterpriseEmploymentService.page(Condition.getPage(query), queryWrapper);
//		List<EnterpriseEmploymentVO> enterpriseEmploymentVOS = enterpriseEmploymentWrapper.entityToVO(pages.getRecords());
//		ListResult<EnterpriseEmploymentVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//		listResult.setList(enterpriseEmploymentVOS);
//		listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//		return listResult;
//	}
//
//
//
//	/**
//	* 新增或修改 企业用工管理主表
//	*/
//	@PostMapping("/submit")
//	@Resubmit(delaySeconds = 0)
//	public R submit(@Valid @RequestBody EnterpriseEmployment enterpriseEmployment) {
//		boolean result = enterpriseEmploymentService.saveOrUpdate(enterpriseEmployment);
//		HashMap<String, Object> processVariable = new HashMap<>();
//		formWorkflowService.startProcessAndSimulate(String.valueOf(enterpriseEmployment.getId()),enterpriseEmployment.getFormType(),processVariable);
//
//		return result ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}
//
//	/**
//	* 删除 企业用工管理主表
//	*/
//	@PostMapping("/remove")
//	public R remove(@RequestBody PageData pd) {
//		List<String> ids = (List<String>)pd.get("ids");
//		return enterpriseEmploymentService.deleteLogic(Func.toLongList(StringUtils.join(ids, StringPool.COMMA)))
//				? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}
//
//
	@PostMapping("/report")
	public ObjResult reportTable(@RequestBody EnterpriseEmploymentDTO enterpriseEmploymentDTO) {
		ReportReturnVO reportReturnVO = enterpriseEmploymentService.report(enterpriseEmploymentDTO);
		ObjResult objResult = new ObjResult(CommonCode.SUCCESS);
		if (Optional.ofNullable(reportReturnVO).isPresent()){
			PageData pd = new PageData();
			pd.put("grids", reportReturnVO.getGrids());
			objResult.setPageData(pd);
		}
		return objResult;

	}
//
//	/**
//	 * 分页 用于招聘管理添加按钮获取上游单据
//	 */
//	@PostMapping("/refList")
//	public ListResult<EnterpriseEmploymentVO> refList(@Valid @RequestBody Query query) {
//		if(query.getAscs()==null&&query.getDescs()==null){
//			query.setDescs("create_time");
//		}
//		List<SearchEntity> entityList = query.getSearch();
//		QueryWrapper<EnterpriseEmployment> queryWrapper = SearchParamEntiy.getQueryWrapper(
//				Condition.getQueryWrapper(new EnterpriseEmployment()), entityList
//		);
//		queryWrapper.eq("company_name_id", TokenUtil.getTokenOrgId());
//		queryWrapper.eq("status", FormStatusConstant.FINISH);
//
//		IPage<EnterpriseEmployment> pages = enterpriseEmploymentService.page(Condition.getPage(query), queryWrapper);
//		List<EnterpriseEmploymentVO> enterpriseEmploymentVOS = enterpriseEmploymentWrapper.entityToVO(pages.getRecords());
//		ListResult<EnterpriseEmploymentVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//		listResult.setList(enterpriseEmploymentVOS);
//		listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//		return listResult;
//	}

}
